package com.xin.motion
{
/**
 * 序列化执行动画
 * @author daichangxin
 */
public class SquenceAnimation extends AnimationBase
{
	private var _animationList:Vector.<AnimationBase>;
	/**
	 * 子项动画开始播放的起点
	 */
	private var _itemAnimationStartElapsed:uint = 0;
	
	public function SquenceAnimation()
	{
		super(0);
		
		init();
	}
	
	private function init():void
	{
		_animationList= new Vector.<AnimationBase>();
	}

	override public function set elapsed(value : uint) : void
	{
		if (_animationList.length == 0) return;
		
		super.elapsed = value;
		var currentAnimation:AnimationBase = _animationList[0];
		var itemAnimationElapsed:uint = value - _itemAnimationStartElapsed;
		//如果帧频超过当前动画帧频，则播放下一个动画
		if (itemAnimationElapsed > currentAnimation.duration)
		{
			_itemAnimationStartElapsed += currentAnimation.duration;
			_animationList.shift();
			this.elapsed = value;
		}
		//不超过，则播放当前动画
		else
		{
			currentAnimation.elapsed = itemAnimationElapsed;
		}
	}
	
	/**
	 * 添加缓动到队列
	 */
	public function push(animation:AnimationBase):void
	{
		_animationList.push(animation);
		_duration += animation.duration;
	}
}
}
